package com.causelist.utils;


public class CauseListUtility {
	
	public static boolean emptyLineFlag = false;
	public static boolean newRecordFlag = false;
	
	public static boolean isCourtName(String line)
	{
		if(null!=line &&  ( line.contains(CauseListConstants.COURT) || line.contains(CauseListConstants.COU)))
		{
			return true;
		}
		return false;
	}
	
	public static boolean isJusticeName(String line)
	{
		if(null!=line &&  ( line.contains(CauseListConstants.HONOURABLE) || line.contains(CauseListConstants.HON)))
		{
			return true;
		}
		return false;
	}
	
	public static String extractJusticeName(String line)
	{
		String justiceName = null;
		if(
				(line.contains(CauseListConstants.MISTER) || line.contains(CauseListConstants.MISS) && line.contains(CauseListConstants.JUSTICE)) 
				
		   )
		{
			justiceName = line.substring((line.indexOf(CauseListConstants.JUSTICE) +  CauseListConstants.JUSTICE.length() + 1) , line.length());
		}
		
		return justiceName;
	}
	
	public static boolean isNewRecord(String line)
	{
		
		String firstCharacter = null;
		char lineFirstChar;
		lineFirstChar = line.charAt(0);
		if(lineFirstChar == ' ')
		{
			return false;
		}
		else
		{
			firstCharacter = String.valueOf(lineFirstChar).trim();
			if(!"".equals(firstCharacter) && 0 < Integer.parseInt(firstCharacter))
			{
				newRecordFlag = true;
				return true;
			}
		}
		
		
		return false;
	}
	
	
	public static boolean isEmptyLine(String line)
	{
		if(line.trim().equals(""))
		{
			emptyLineFlag = true;
			return true;
		}
		return false;
	}
	
	public static int returnSmallerNumber(int number,int lineLength)
	{
		if(number<lineLength)
			return number;
		else
			return lineLength;
	}
	
	public static String trim(String value)
	{
		if(null != value && !"".equals(value))
				return value.trim();
		else
			return value;
	}
	
	public static String wrapToSingleLine(String input)
	{
		String output = "";
		if(input != null && !"".equals(input))
		{
			output = input.trim().replace("\n", " ");
		}
		return output;
	}
	
	public static String clipText(String value , String destination)
	{
		int length = 0;
		// clipping individual field
		if(destination.equals("DB"))
		{
			length =  300;	
		}
		else if(destination.equals("SMS")) // clipping entire sms
		{
			length = 160 ;
		}
		
		value = value.substring(0, length);
		return value;
	}
	{
		
	}


}
